function isSelfDividing(num) {
  let tmp = num
  while (tmp > 0) {
    const digit = tmp % 10
    if (digit === 0 || num % digit !== 0) return false
    tmp = Math.floor(tmp / 10)
  }
  return true
}

/**
 * @param {number} left
 * @param {number} right
 * @return {number[]}
 */
export var selfDividingNumbers = function (left, right) {
  const resLeft = []
  const resRight = []
  while (left <= right) {
    if (isSelfDividing(left)) resLeft.push(left)
    if (left === right) break
    if (isSelfDividing(right)) resRight.unshift(right)
    left++
    right--
  }
  return resLeft.concat(resRight)
}
